<?php
/**
 * 用户中心
 * Create by PhpStorm
 * User: lijia
 * Data: 2020/8/10
 * Time: 14:50
 */

namespace app\api\controller;

use app\api\business\CashBus;
use think\facade\Db;

class Cash extends UserCommon
{

    public function __construct(){
        parent::__construct();
    }

    /**
     * 申请提现
     * @return \think\response\Json
     */
    public function toCash(){
        $post = input('param.','','trim');
        if (!$post['amount'] || $post['amount']%100 != 0){
            return resJson(0,'金额只能是100的倍数');
        }
        Db::startTrans();
        try{
            (new CashBus())->todo($post);
            Db::commit();
            return resJson(200,'提交成功');
        }catch (\Exception $e){
            Db::rollback();
            return resJson(0,$e->getMessage());
        }
    }

    /**
     * 提现列表
     * @return \think\response\Json
     */
    public function getList(){
        $status = input('param.status',0,'intval');
        try{
            $data = (new CashBus())->getList($status);
            return resJson(200,'ok',$data);
        }catch (\Exception $e){
            return resJson($e->getCode(),$e->getMessage());
        }
    }

}